/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Libros;
import Tablas.Libros;
import java.util.Iterator;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author carlosenriquez
 */
public class Update {
    public static void main(String args[]){
        Session session = null;
        try{
            Configuration configuration=new Configuration();
            SessionFactory sessionFactory=configuration.configure().buildSessionFactory();
            session=sessionFactory.openSession();
            Transaction transaction=session.beginTransaction();
            
            String HQL_QUERY="from Libros libros where libros.idLibros = :id_Libros";
            org.hibernate.Query query=session.createQuery(HQL_QUERY);
            
            //preparar sentencia
            query.setParameter("id_Libros", 3);
//            query.setParameter("Titulo", "qwerty");
            for(Iterator it=query.iterate(); it.hasNext();){
                 Libros lib= (Libros) it.next();
                 lib.setTitulo("Ruiz");
            }
            transaction.commit();
            System.out.println("Hecho!");
        }catch(Exception e){ 
            System.out.println(e.getMessage());
        }
        finally{
            session.flush();
            session.close();
        }
    }
    
}
